import {PureComponent} from "react";
import store from "./store";
import {addAction, subAction} from './store/modules/count/actionGenerator'

export class Count extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            count: store.getState().count.count,
        }
    }

    componentDidMount() {
        store.subscribe(() => {
            this.setState({count: store.getState().count.count})
        })
    }

    addClick(num) {
        store.dispatch(addAction(num))
    }

    subClick(num) {
        store.dispatch(subAction(num))
    }

    render() {
        const {count} = this.state;
        return (
            <div>
                <div>count page开始</div>
                <div>{count}</div>
                <button onClick={() => this.addClick(1)}>+1</button>
                <button onClick={() => this.subClick(1)}>-1</button>
                <div>count page结束</div>
            </div>
        )
    }
}